import { observable, action, runInAction } from "mobx";
import HomeApi from "../api/home";
const getData = (length = 10) => {
  return Array.from({ length }).map((item, index) => {
    return {
      id: `2018090${index}`,
      key: `200920${index}`,
      name: `iotApp0${index}`,
      platform: "ANDROID",
      status: "正常"
    };
  });
};

class HomeStore {
  @observable data = [];
  @observable current = 1;
  @observable isLoading = true;

  constructor() {}

  @action initData = async () => {
    const data = await HomeApi.getList();
    //runInAction的作用是统一设置状态
    runInAction("获取首页列表", () => {
      this.data = data;
      this.isLoading = false;
    });
  };

  @action handlePaginationChange = current => {
    this.current = current;
    this.data = getData(current);
  };
}

export default new HomeStore();
